package sctu.edu.java.year2016.team01.chenhong.day20160616.chapter15_3;


import javax.swing.JProgressBar;
import java.awt.BorderLayout;
import javax.swing.*;

/**
 * Created by Administrator on 2016/6/16.
 *尝试开发一个窗体，在窗体中设计一个进度条，是进度条每次递增滚动。
 */
public class Progress extends JFrame {
    private Thread thread;
    final JProgressBar progressBar = new JProgressBar();
    int count = 0;

    public static void main(String[] args) {
        init(new Progress(), 300, 300);
    }



    private static void init(JFrame frame, int width, int height) {

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);
        frame.setVisible(true);

    }

    public Progress() {
        super();
        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);
        thread = new Thread(new Runnable() {
            int count = 0;

            public void run() {
                while (true) {
                    progressBar.setValue(++count);

                    try {
                        thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }
            }

        });
        thread.start();
    }
}